{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multilabel Classification with Python\n",
    "\n",
    "##### Multilabel Dataset Examples\n",
    "+ https://sci2s.ugr.es/keel/multilabel.php#sub10\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "![](multi-class_vs_multi_label_classification_jcharistech.png)\n",
    "\n",
    "#### Solution for Multi-Label Problem\n",
    "+ Methods for solving Multi-label Classification Problems\n",
    "    + Problem Transformation\n",
    "    + Adapted Algorithm\n",
    "    + Ensemble approaches\n",
    "\n",
    "#### Problem Transformation\n",
    "+ It refers to transforming the multi-label problem into single-label problem(s) by using\n",
    "    - Binary Relevance: treats each label as a separate single class classification\n",
    "    - Classifier Chains:In this, the first classifier is trained just on the input data and then each next classifier is trained on the input space and all the previous classifiers in the chain.\n",
    "    - Label Powerset:we transform the problem into a multi-class problem with one multi-class classifier is trained on all unique label combinations found in the training data.\n",
    "\n",
    "        \n",
    "#### Adapted Algorithm\n",
    "+ adapting the algorithm to directly perform multi-label classification, rather than transforming the problem into different subsets of problems.\n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load EDA Pkgs\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.7/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n",
      "  import pandas.util.testing as tm\n"
     ]
    }
   ],
   "source": [
    "# Load Data Viz Pkgs\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ML Pkgs\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.naive_bayes import GaussianNB,MultinomialNB\n",
    "from sklearn.metrics import accuracy_score,hamming_loss,classification_report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Split Dataset into Train and Text\n",
    "from sklearn.model_selection import train_test_split\n",
    "# Feature engineering\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multi Label Pkgs\n",
    "from skmultilearn.problem_transform import BinaryRelevance\n",
    "from skmultilearn.problem_transform import ClassifierChain\n",
    "from skmultilearn.problem_transform import LabelPowerset\n",
    "from skmultilearn.adapt import MLkNN\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install scikit-multilearn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Dataset\n",
    "df = pd.read_csv(\"data/so_dataset_2_tags.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>tags</th>\n",
       "      <th>mysql</th>\n",
       "      <th>python</th>\n",
       "      <th>php</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Flask-SQLAlchemy - When are the tables/databas...</td>\n",
       "      <td>['python', 'mysql']</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Combining two PHP variables for MySQL query</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>'Counting' the number of records that match a ...</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Insert new row in a table and auto id number. ...</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Create Multiple MySQL tables using PHP</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               title                 tags  \\\n",
       "0  Flask-SQLAlchemy - When are the tables/databas...  ['python', 'mysql']   \n",
       "1        Combining two PHP variables for MySQL query     ['php', 'mysql']   \n",
       "2  'Counting' the number of records that match a ...     ['php', 'mysql']   \n",
       "3  Insert new row in a table and auto id number. ...     ['php', 'mysql']   \n",
       "4             Create Multiple MySQL tables using PHP     ['php', 'mysql']   \n",
       "\n",
       "   mysql  python  php  \n",
       "0      1     1.0  0.0  \n",
       "1      1     0.0  1.0  \n",
       "2      1     0.0  1.0  \n",
       "3      1     0.0  1.0  \n",
       "4      1     0.0  1.0  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Flask-SQLAlchemy - When are the tables/databases created and destroyed?'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[0].title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title      object\n",
       "tags       object\n",
       "mysql       int64\n",
       "python    float64\n",
       "php       float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Convert to Float\n",
    "df['mysql'] = df['mysql'].astype(float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title      object\n",
       "tags       object\n",
       "mysql     float64\n",
       "python    float64\n",
       "php       float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fee6c58a790>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0d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eBbwzCRj3fZzGNz9fB7wP1W1vKpe1W1bBryrqp4FPAD8dtd+OfDmqnoOcAuDu1N3mV9VJwPnzmiXRsLgl+AbVfUf3fI/A6cB7wdenWQBcCrwb3vo+9Wquqlb3gQsTfJUYEFVfaprnwBeOK3PtdP3f3z+CdLwnKtHgpnzlhRwGfAR4PvAB7tnFszmB9OWHwGOHOJ4u/o8gv8HNQc845fguCSndsu/C3ymqr4JfBP4cwZfArv8KMlhe/uwqnoQuH/a+P1rgE/tpYs0Uga/BHcAr0uyGVjIo894vYLBMNDmafuuA26e9uPunqwG3pbkZmA5cMHjXLO035ydU01LshT4aFU9e5Zt7wS+VFWXjrouqU+OL0qzSLIJeBh401zXIj3ePOOXpMY4xi9JjTH4JakxBr8kNcbgl6TGGPyS1Jj/A8FENWB7O9y9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Value Count \n",
    "sns.countplot(df['python'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fee6c783390>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAQNUlEQVR4nO3df6xfd13H8eeLdnMMgXXrpXYrs4tbhovCgJu5CTG6Mh2ItCFzGQpcsbEmIoL4g+kfDFATFtE5p2IaBtwhjo2y2WoMupQhQWFwO+Z+sqzMDVq79W5sjB8KFt/+8T2Vu9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Mp+r9ur6rUjqEtaFK/4JakxzscvSY3xil+SGmPwS1JjDH5JaozBL0mNMfglqTH/B0Ah/0HGjqnlAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Value Count \n",
    "sns.countplot(df['php'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0    82\n",
       "0.0    62\n",
       "Name: php, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['php'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fee69ec1990>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD+CAYAAAAj1F4jAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAOQklEQVR4nO3df6xfd13H8eeLlWb8ULayr9fSMru4BjJNNvBmjmBMXJkOIbR/kGXE6A1pUhNFQUyk+g8h8Y8tMSImRm0YeE1wP5ybrcOgS91ijFq4GxPYBraMDdp07QU2+WECDN7+cc9s99337p7e+/3eL5/b5yO5+Z7zOef0vP64eeXTc8/5nlQVkqT2vGjaASRJq2OBS1KjLHBJapQFLkmNssAlqVGb1vNkl1xySe3YsWM9TylJzXvggQe+WlWD4fF1LfAdO3awsLCwnqeUpOYleWLUuJdQJKlRFrgkNcoCl6RGWeCS1CgLXJIaZYFLUqMscElql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o/JTkv4GfqqrvDY1vBh72PvDJcQa+MXxg2gF0XvsB8KoR41u7bZqQib/UWOOR5DPLbQJ8pF7T9B7gcJKjnLnF9VLgcsDbWyfISyiNSHIK+CXgqeFNwL9X1agZkLQukrwIuJrn/hHzU1X1/eml2vicgbfjHuDlVfXQ8IYk969/HOmMqvoB8J/TznG+cQYuSY3yj5iS1CgLXJIaZYFLUqMscElq1P8B7V1sXLJXT0YAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "df['php'].value_counts().plot(kind='bar')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Text Preprocessing\n",
    "+ neattext : remove_stopwords\n",
    "+ pip install neattext"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import neattext as nt\n",
    "import neattext.functions as nfx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      {'text_noise': 11.267605633802818, 'text_lengt...\n",
       "1      {'text_noise': 4.651162790697675, 'text_length...\n",
       "2      {'text_noise': 9.90990990990991, 'text_length'...\n",
       "3      {'text_noise': 8.47457627118644, 'text_length'...\n",
       "4      {'text_noise': 2.631578947368421, 'text_length...\n",
       "                             ...                        \n",
       "139    {'text_noise': 26.41509433962264, 'text_length...\n",
       "140    {'text_noise': 3.8461538461538463, 'text_lengt...\n",
       "141    {'text_noise': 6.666666666666667, 'text_length...\n",
       "142    {'text_noise': 13.636363636363635, 'text_lengt...\n",
       "143    {'text_noise': 7.142857142857142, 'text_length...\n",
       "Name: title, Length: 144, dtype: object"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Explore For Noise\n",
    "df['title'].apply(lambda x:nt.TextFrame(x).noise_scan())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                                [when, are, the, and]\n",
       "1                                           [two, for]\n",
       "2                    [the, of, that, a, and, the, and]\n",
       "3                                    [in, a, and, and]\n",
       "4                                              [using]\n",
       "                            ...                       \n",
       "139                                 [where, in, using]\n",
       "140                                               [to]\n",
       "141                                  [and, get, using]\n",
       "142    [how, to, the, of, a, with, a, back, into, the]\n",
       "143                                           [in, if]\n",
       "Name: title, Length: 144, dtype: object"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Explore For Noise\n",
    "df['title'].apply(lambda x:nt.TextExtractor(x).extract_stopwords())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['CURRENCY_REGEX',\n",
       " 'CURRENCY_SYMB_REGEX',\n",
       " 'DATE_REGEX',\n",
       " 'EMAIL_REGEX',\n",
       " 'EMOJI_REGEX',\n",
       " 'MOST_COMMON_PUNCT_REGEX',\n",
       " 'NUMBERS_REGEX',\n",
       " 'PHONE_REGEX',\n",
       " 'SPECIAL_CHARACTERS_REGEX',\n",
       " 'STOPWORDS',\n",
       " 'STOPWORDS_de',\n",
       " 'STOPWORDS_en',\n",
       " 'STOPWORDS_es',\n",
       " 'STOPWORDS_fr',\n",
       " 'STOPWORDS_ru',\n",
       " 'STOPWORDS_yo',\n",
       " 'TextFrame',\n",
       " 'URL_PATTERN',\n",
       " '__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__generate_text',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__numbers_dict',\n",
       " '__package__',\n",
       " '__spec__',\n",
       " '_lex_richness_herdan',\n",
       " '_lex_richness_maas_ttr',\n",
       " 'clean_text',\n",
       " 'defaultdict',\n",
       " 'digit2words',\n",
       " 'extract_currencies',\n",
       " 'extract_currency_symbols',\n",
       " 'extract_dates',\n",
       " 'extract_emails',\n",
       " 'extract_emojis',\n",
       " 'extract_html_tags',\n",
       " 'extract_numbers',\n",
       " 'extract_phone_numbers',\n",
       " 'extract_special_characters',\n",
       " 'extract_stopwords',\n",
       " 'extract_urls',\n",
       " 'fix_contractions',\n",
       " 'generate_sentence',\n",
       " 'hamming_distance',\n",
       " 'inverse_df',\n",
       " 'lexical_richness',\n",
       " 'markov_chain',\n",
       " 'math',\n",
       " 'nlargest',\n",
       " 'normalize',\n",
       " 'num2words',\n",
       " 'random',\n",
       " 're',\n",
       " 'read_txt',\n",
       " 'remove_bad_quotes',\n",
       " 'remove_currencies',\n",
       " 'remove_currency_symbols',\n",
       " 'remove_custom_words',\n",
       " 'remove_dates',\n",
       " 'remove_emails',\n",
       " 'remove_emojis',\n",
       " 'remove_html_tags',\n",
       " 'remove_multiple_spaces',\n",
       " 'remove_non_ascii',\n",
       " 'remove_numbers',\n",
       " 'remove_phone_numbers',\n",
       " 'remove_puncts',\n",
       " 'remove_punctuations',\n",
       " 'remove_special_characters',\n",
       " 'remove_stopwords',\n",
       " 'remove_urls',\n",
       " 'replace_bad_quotes',\n",
       " 'replace_currencies',\n",
       " 'replace_currency_symbols',\n",
       " 'replace_dates',\n",
       " 'replace_emails',\n",
       " 'replace_emojis',\n",
       " 'replace_numbers',\n",
       " 'replace_phone_numbers',\n",
       " 'replace_special_characters',\n",
       " 'replace_term',\n",
       " 'replace_urls',\n",
       " 'string',\n",
       " 'term_freq',\n",
       " 'to_txt',\n",
       " 'word_freq',\n",
       " 'word_length_freq']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(nfx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      Flask-SQLAlchemy - tables/databases created de...\n",
       "1                    Combining PHP variables MySQL query\n",
       "2      'Counting' number records match certain criter...\n",
       "3         Insert new row table auto id number. Php MySQL\n",
       "4                       Create Multiple MySQL tables PHP\n",
       "                             ...                        \n",
       "139               Executing \"SELECT ... ... ...\" MySQLdb\n",
       "140                              SQLAlchemy reconnect db\n",
       "141                      mysql Count Distinct result php\n",
       "142    store result radio button database value, data...\n",
       "143                 Use SQL count result statement - PHP\n",
       "Name: title, Length: 144, dtype: object"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Explore For Noise\n",
    "df['title'].apply(nfx.remove_stopwords)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "corpus = df['title'].apply(nfx.remove_stopwords)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Feature Engineering\n",
    "+ Build features from our text\n",
    "+ TFIDF,countvectorizer,bow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "tfidf = TfidfVectorizer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TfidfVectorizer(analyzer='word', binary=False, decode_error='strict',\n",
       "                dtype=<class 'numpy.float64'>, encoding='utf-8',\n",
       "                input='content', lowercase=True, max_df=1.0, max_features=None,\n",
       "                min_df=1, ngram_range=(1, 1), norm='l2', preprocessor=None,\n",
       "                smooth_idf=True, stop_words=None, strip_accents=None,\n",
       "                sublinear_tf=False, token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b',\n",
       "                tokenizer=None, use_idf=True, vocabulary=None)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tfidf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Build Features\n",
    "Xfeatures = tfidf.fit_transform(corpus).toarray()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xfeatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>tags</th>\n",
       "      <th>mysql</th>\n",
       "      <th>python</th>\n",
       "      <th>php</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Flask-SQLAlchemy - When are the tables/databas...</td>\n",
       "      <td>['python', 'mysql']</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Combining two PHP variables for MySQL query</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>'Counting' the number of records that match a ...</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Insert new row in a table and auto id number. ...</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Create Multiple MySQL tables using PHP</td>\n",
       "      <td>['php', 'mysql']</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               title                 tags  \\\n",
       "0  Flask-SQLAlchemy - When are the tables/databas...  ['python', 'mysql']   \n",
       "1        Combining two PHP variables for MySQL query     ['php', 'mysql']   \n",
       "2  'Counting' the number of records that match a ...     ['php', 'mysql']   \n",
       "3  Insert new row in a table and auto id number. ...     ['php', 'mysql']   \n",
       "4             Create Multiple MySQL tables using PHP     ['php', 'mysql']   \n",
       "\n",
       "   mysql  python  php  \n",
       "0    1.0     1.0  0.0  \n",
       "1    1.0     0.0  1.0  \n",
       "2    1.0     0.0  1.0  \n",
       "3    1.0     0.0  1.0  \n",
       "4    1.0     0.0  1.0  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = df[['mysql', 'python', 'php']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Split Data \n",
    "X_train,X_test,y_train,y_test = train_test_split(Xfeatures,y,test_size=0.3,random_state=42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(144,)\n",
      "(100, 404)\n"
     ]
    }
   ],
   "source": [
    "print(df['title'].shape)\n",
    "print(X_train.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Building Our Model\n",
    "# Estimator + Multilabel Estimator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Problem Transform\n",
    "import skmultilearn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__path__',\n",
       " '__spec__',\n",
       " 'adapt',\n",
       " 'base',\n",
       " 'problem_transform',\n",
       " 'utils']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(skmultilearn)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Binary Relevance classficiation\n",
    "+ Convert Our Multi-Label Prob to Multi-Class\n",
    "\n",
    "![](binary_relevance_multilabel_ml_jcharistech.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Convert Our Multi-Label Prob to Multi-Class\n",
    "# binary classficiation\n",
    "binary_rel_clf = BinaryRelevance(MultinomialNB())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "BinaryRelevance(classifier=MultinomialNB(alpha=1.0, class_prior=None,\n",
       "                                         fit_prior=True),\n",
       "                require_dense=[True, True])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binary_rel_clf.fit(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Predictions\n",
    "br_prediction = binary_rel_clf.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<44x3 sparse matrix of type '<class 'numpy.float64'>'\n",
       "\twith 88 stored elements in Compressed Sparse Column format>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "br_prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 0., 1.],\n",
       "       [1., 1., 0.],\n",
       "       [1., 1., 0.]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Convert to Array  To See Result\n",
    "br_prediction.toarray()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9090909090909091"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Accuracy\n",
    "accuracy_score(y_test,br_prediction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.06060606060606061"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Hamming Loss :Incorrect Predictions\n",
    "# The Lower the result the better\n",
    "hamming_loss(y_test,br_prediction)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Classifier Chains\n",
    "+ Preserve Label Correlation\n",
    "\n",
    "![](classifier_chains_multilabel_jcharistech.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [],
   "source": [
    "def build_model(model,mlb_estimator,xtrain,ytrain,xtest,ytest):\n",
    "    # Create an Instance\n",
    "    clf = mlb_estimator(model)\n",
    "    clf.fit(xtrain,ytrain)\n",
    "    # Predict\n",
    "    clf_predictions = clf.predict(xtest)\n",
    "    # Check For Accuracy\n",
    "    acc = accuracy_score(ytest,clf_predictions)\n",
    "    ham = hamming_loss(ytest,clf_predictions)\n",
    "    result = {\"accuracy:\":acc,\"hamming_score\":ham}\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_chain_model = build_model(MultinomialNB(),ClassifierChain,X_train,y_train,X_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'accuracy:': 0.8409090909090909, 'hamming_score': 0.10606060606060606}"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_chain_model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### LabelPowerset\n",
    "![](labelPowerset_multilabel_ml_jcharistech.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_labelP_model = build_model(MultinomialNB(),LabelPowerset,X_train,y_train,X_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'accuracy:': 0.9090909090909091, 'hamming_score': 0.06060606060606061}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_labelP_model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Apply On A Simple Ttitle/Question"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "ex1 = df['title'].iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Vectorized \n",
    "vec_example = tfidf.transform([ex1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 0.]])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Make our prediction\n",
    "binary_rel_clf.predict(vec_example).toarray()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "import joblib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save Model\n",
    "binary_rel_clf_file = open(\"binary_rel_clf_model_file.pkl\",\"wb\")\n",
    "joblib.dump(binary_rel_clf,binary_rel_clf_file)\n",
    "binary_rel_clf_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save Vectorizer\n",
    "tfidf_vectorizer_file = open(\"tfidf_vectorizer_SO_tags_file.pkl\",\"wb\")\n",
    "joblib.dump(tfidf,tfidf_vectorizer_file)\n",
    "tfidf_vectorizer_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### Adapted Algorithm\n",
    "from skmultilearn.adapt import MLkNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Thanks For Watching \n",
    "### Jesus Saves @JCharisTech\n",
    "### Jesse E.Agbe(JCharis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
